package com.zj.eswrapper.utils;

import com.zj.eswrapper.enums.OperatorEnum;
import com.zj.eswrapper.enums.OrderEnum;
import com.zj.eswrapper.enums.ScoreModeEnum;
import org.apache.lucene.search.join.ScoreMode;
import org.elasticsearch.index.query.Operator;
import org.elasticsearch.search.sort.SortOrder;

import java.util.Objects;

/**
 * @author arthur_zhou
 */
public class FieldValueUtil {

    /**
     * 排序
     *
     * @param orderEnum
     * @return
     */
    public static SortOrder sortOrder(OrderEnum orderEnum) {
        if (Objects.isNull(orderEnum)) {
            return SortOrder.ASC;
        }
        return orderEnum == OrderEnum.ASC ? SortOrder.ASC : SortOrder.DESC;
    }

    public static Operator operator(OperatorEnum operatorEnum) {
        if (Objects.isNull(operatorEnum)) {
            return null;
        }
        switch (operatorEnum) {
            case OR:
                return Operator.OR;
            case AND:
                return Operator.AND;
            default:
                return null;
        }
    }

    public static ScoreMode scoreMode(ScoreModeEnum scoreMode) {
        if (Objects.isNull(scoreMode)) {
            return ScoreMode.None;
        }
        switch (scoreMode) {
            case AVG:
                return ScoreMode.Avg;
            case TOTAL:
                return ScoreMode.Total;
            case MAX:
                return ScoreMode.Max;
            case MIN:
                return ScoreMode.Min;
            default:
                return ScoreMode.None;
        }
    }
}
